home *** CD-ROM | disk | FTP | other *** search
- Path: news.umbc.edu!not-for-mail
- From: schlein@umbc.edu (Jonas J. Schlein)
- Newsgroups: comp.lang.c
- Subject: Re: Towers of Hanoi
- Date: 3 Mar 1996 16:38:19 -0500
- Organization: University of Maryland Baltimore County
- Message-ID: <4hd3gb$4v9@umbc9.umbc.edu>
- References: <4h5gq7$bmo@useneta1.news.prodigy.com>
- NNTP-Posting-Host: umbc9.umbc.edu
- NNTP-Posting-User: schlein
-
- Craig Bellet <ELFW44A@prodigy.com> wrote:
- |> Learning to program in C++. Assigned problem of moving four progressively
- |> larger rings sitting on a peg to another peg one ring at a time. The
- |> object is to move the stack of rings to another peg. A small ring may be
- |> placed upon a larger ring or an empty peg but not upon a larger ring. A
- |> third peg is to facilitate this by temporarily holding rings. The
- |> solution involves recursion but I am unable to figure out the algorithm.
- |> Any thoughts?
-
- Assigned you say? I say do you own homework...On a side note the solution
- to this is very easily done recursively, but an iterative version using
- a user defined stack isn't much harder (maybe longer). Many books also
- have solutions with complete code. You just have to look. I have a solution
- in Pascal from "Pascal" 4th Edition by Elliott B. Koffman. The solution
- they gave is approx 10 lines of code. Give it some thought and try to do
- small test cases by hand to get the algorithm down pat.
- --
- "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
-
- Jonas J. Schlein (schlein@gl.umbc.edu)
-